<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('结项课题申请')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-apply-add" th:object="${sciIntraSchoolPro}">

        <input name="id" id="ktid" th:field="*{id}" type="hidden">
        <input type="hidden" name="state" value="7">

        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">申请人：</label>
                    <div class="col-sm-8">
                        <input  readonly th:field="*{userName}" class="form-control" type="text" >
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题类型：</label>
                    <div class="col-sm-8">
                        <input readonly name="topName"  class="form-control" type="text" required th:value="${topType == 'technical_dev' ? '技术服务' : '技术开发（委托）'}">

                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题名称：</label>
                    <div class="col-sm-8">
                        <input readonly name="topName" th:field="*{topName}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">项目金额：</label>
                    <div class="col-sm-8">
                        <input readonly name="amount" th:field="*{amount}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>


            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">甲方：</label>
                    <div class="col-sm-8">
                        <input readonly th:field="*{pa}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">乙方：</label>
                    <div class="col-sm-8">
                        <input readonly th:field="*{pb}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>


            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">立项日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date" >
                            <input readonly name="signingData" autocomplete="off" th:field="*{signingData}" th:value="${#dates.format(signingData, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
<!--            <div class="col-xs-6">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label is-required">结项日期：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <div class="input-group date">-->
<!--                            <input autocomplete="off" name="validityDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>-->
<!--                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">结项日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input readonly autocomplete="off" name="validityDate" th:field="*{validityDate}" th:value="${#dates.format(signingData, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">第一负责人：</label>
                    <div class="col-sm-8">
                        <select name="firstPersonId" class="form-control m-b" disabled >
                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciIntraSchoolPro.firstPersonId}" readonly></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">第二负责人：</label>
                    <div class="col-sm-8">
                        <!--                        <input name="secondPersonTask" th:field="*{secondPersonTask}" class="form-control" type="text" required>-->
                        <select name="secondPersonId" class="form-control m-b" disabled>
                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciIntraSchoolPro.secondPersonId}" readonly></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">第三负责人：</label>
                    <div class="col-sm-8">
                        <!--                        <input name="thirdPersonId" th:field="*{thirdPersonId}" class="form-control" type="text" required>-->
                        <select name="thirdPersonId" class="form-control m-b" disabled>
                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciIntraSchoolPro.thirdPersonId}" readonly ></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">第四负责人：</label>
                    <div class="col-sm-8">
                        <!--                        <input name="fourthPersonId" th:field="*{fourthPersonId}" class="form-control" type="text" required>-->
                        <select name="fourthPersonId" class="form-control m-b" disabled>
                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciIntraSchoolPro.fourthPersonId}" readonly ></option>
                        </select>
                    </div>
                </div>
            </div>



            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">合同：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="overContract">
                        <div class="file-loading">
                            <input class="form-control file-upload1" id="overContract" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">备案表：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="overFiling">
                        <div class="file-loading">
                            <input class="form-control file-upload2" id="overFiling" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: select2-js" />

<script th:inline="javascript">
    var prefix = ctx + "IntraSchPro"
    $("#form-apply-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            if ($("input[name='overContract']").val() == "") {
                $.modal.alertWarning("请上传合同");
                return;
            }else if ($("input[name='overFiling']").val() == ""){
                $.modal.alertWarning("请上传备案表");
                return;
            }
            $.operate.saveTab(prefix + "/sch_overadd", $('#form-apply-add').serialize());
        }
    }
    $("input[name='validityDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });


    // $(".file-upload").fileinput({
    //     uploadUrl: ctx + 'common/upload',
    //     maxFileCount: 1,
    //     autoReplace: true,
    //     allowedFileExtensions: ["pdf"]  //指定上传文件类型
    // }).on('fileuploaded', function (event, data, previewId, index) {
    //     $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    // }).on('fileremoved', function (event, id, index) {
    //     $("input[name='" + event.currentTarget.id + "']").val('')
    // })
    $(".file-upload1").fileinput({
        //prefix+"/upload",
        uploadUrl:  ctx + 'common/upload/cgzh',
        maxFileCount: 1,
        autoReplace: true,
        allowedFileExtensions: ["pdf"],  //指定上传文件类型
        slugCallback: function(filename) {
            if ($("input[name='topName']").val()===""){
                $(".file-upload1").fileinput('clear');
                $.modal.alertError("请先输入课题名称");
                return false;
            }
            // 自定义文件名生成规则
            fileExtension = filename.split('.').pop();
            const year = new Date().getFullYear();
            const newName = year +"-"+ $("input[name='topName']").val() +"-"+ "合同"+ "." + fileExtension;
            return newName;
        },
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })

    $(".file-upload2").fileinput({
        //prefix+"/upload",
        uploadUrl:  ctx + 'common/upload/cgzh',
        maxFileCount: 1,
        autoReplace: true,
        allowedFileExtensions: ["pdf"],  //指定上传文件类型
        slugCallback: function(filename) {
            if ($("input[name='topName']").val()===""){
                $(".file-uploadb").fileinput('clear');
                $.modal.alertError("请先输入课题名称");
                return false;
            }
            // 自定义文件名生成规则
            fileExtension = filename.split('.').pop();
            const year = new Date().getFullYear();
            const newName = year +"-"+ $("input[name='topName']").val() +"-"+ "备案表"+ "." + fileExtension;
            return newName;
        },
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
</script>
</body>
</html>
